package com.example.greetingcard

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

// NotificationsFragment.kt
class NotificationsFragment : Fragment() {


    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.notifications_fragment, container, false)
        val recyclerView = view.findViewById<RecyclerView>(R.id.recyclerViewNotifications)

        // 准备示例数据（包含 NotificationItem 对象）
        val dataList = listOf(
            NotificationItem("新消息", "您有一条未读消息"),
            NotificationItem("系统通知", "版本更新已完成"),
            NotificationItem("活动提醒", "今日下午3点会议开始")
        )

        // 设置布局管理器和适配器
        recyclerView.layoutManager = LinearLayoutManager(requireContext())
        recyclerView.adapter = NotificationAdapter(dataList)

        return view

    }

    private class NotificationAdapter(private val dataList: List<NotificationItem>) :
        RecyclerView.Adapter<NotificationAdapter.ViewHolder>() {

        inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
            val titleTextView: TextView = itemView.findViewById(R.id.title)  // 对应布局中的 ID
            val contentTextView: TextView = itemView.findViewById(R.id.content)  // 对应布局中的 ID
        }

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
            val view = LayoutInflater.from(parent.context)
                .inflate(R.layout.list_item_notification, parent, false)
            return ViewHolder(view)
        }

        override fun onBindViewHolder(holder: ViewHolder, position: Int) {
            val item = dataList[position]
            holder.titleTextView.text = item.title
            holder.contentTextView.text = item.content
        }

        override fun getItemCount(): Int = dataList.size
    }
}




